package com.h5lib.server;

import java.io.IOException;

import com.h5lib.server.protocol.FileDirProtocolProvider;
import com.h5lib.server.protocol.ProtocolRegister;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args ) throws DiException
    {
    	new DiApp(args) {
			
			@Override
			public void startApp() {
				int port = 8082;
				if(args != null && args.length > 0 && args[0] != null){
					port = Integer.valueOf(args[0]);
				}
				CoreWebServer server = new CoreWebServer(port);
				ProtocolRegister.getProtocolRegister().setDefaultProtocolProvider(new FileDirProtocolProvider());
			    try {
			        server.start();
			    } catch (IOException ioe) {
			        System.err.println("Couldn't start server:\n" + ioe);
			        System.exit(-1);
			    }
			    try {
					Class.forName("android.os.Build");
					 System.out.println("Android Os Server started.\n");
				} catch (ClassNotFoundException e) {
			        System.out.println("desktop Os Server started, Hit Enter to stop.\n");
			        try {
			            System.in.read();
			        } catch (Throwable ignored) {
			        }
			        server.stop();
			        System.out.println("Server stopped.\n");
				}
			}
			
			@Override
			public void initDi() throws DiException {
				
			}
		};
    }
}
